package com.oa.business.org;

import com.oa.business.org.dto.PositionDto;
import com.oa.common.result.Result;
import com.oa.framework.org.domain.Position;
import com.oa.framework.org.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 职位API
 * @author cuichao
 */
@RestController
@RequestMapping("post")
public class PositionController {

    @Autowired
    private PositionService positionService;

    @GetMapping("/list")
    public Result list(){
        List<Position> positions = positionService.loadEnablePositions();
        return Result.success(positions);
    }

    @GetMapping("/info/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(positionService.getPosition(id));
    }

    @PostMapping("add")
    public Result add(@RequestBody PositionDto positionDto){
        return Result.success(positionService.addPosition(positionDto.transform()));
    }

    @PostMapping("edit")
    public Result edit(@RequestBody PositionDto positionDto){
        return Result.success(positionService.updatePosition(positionDto.transform()));
    }

    @PostMapping("disable/{id}")
    public Result disable(@PathVariable Long id){
        return Result.success(positionService.disablePosition(id));
    }

}
